//https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&tqId=23450&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13

/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
class Solution {
public:
    ListNode* deleteDuplication(ListNode* pHead) {
        // ListNode* fast = pHead;
        // ListNode* slow = pHead;

        // if(fast == nullptr)
        // {
        //     return nullptr;
        // }
        // if(fast -> next == nullptr)
        // {
        //     return slow;
        // }
        // while(fast)
        // {
        //     if(fast->next->val == fast->val)
        //     {
        //         fast = fast->next;
        //     }

        //     if(fast->val != slow->val)
        //     {
        //         fast = fast->next;
        //         slow = slow->next;
        //     }
        // }
        if(pHead == nullptr)
        {
            return nullptr;
        }
        ListNode* res = new ListNode(0);
        //带头
        res->next = pHead;
        ListNode* cur = res;
        while(cur->next != nullptr && cur->next->next != nullptr)
        {
            if(cur->next->val == cur->next->next->val)
            {
                int temp = cur->next->val;
                while(cur->next != nullptr && cur->next->val == temp)
                {
                    cur->next = cur->next->next;
                }
            }
            else 
            {
                cur = cur->next;
            }
        }
        return res->next;
    }
};